﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;

namespace WindowsFormsApplication
{
    [Serializable]
    class PrintTimeAttribute : PostSharp.Aspects.OnMethodBoundaryAspect
    {
        public override void RuntimeInitialize(System.Reflection.MethodBase method)
        {
            base.RuntimeInitialize(method);
            _sw = new Stopwatch();
        }

        [NonSerialized]
        private System.Diagnostics.Stopwatch _sw;
        public sealed override void OnEntry(PostSharp.Aspects.MethodExecutionArgs args)
        {
            base.OnEntry(args);
            _sw.Restart();
        }

        public sealed override void OnExit(PostSharp.Aspects.MethodExecutionArgs args)
        {
            base.OnExit(args);
            _sw.Stop();
            var time = _sw.ElapsedMilliseconds;
            System.Diagnostics.Debug.WriteLine(args.Method.Name + "took: " + time);
        }
    }
}
